package com.xwj.nio.netty.handler;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.embedded.EmbeddedChannel;

/**
 * @author xwj
 * @date 2020/6/15
 */
public class InputHandlerDemoTest {
    public static void main(String[] args) {
        final InputHandlerDemo inputHandler = new InputHandlerDemo();
        // 创建嵌入式通道
        EmbeddedChannel channel = new EmbeddedChannel(new ChannelInitializer<EmbeddedChannel>() {
            @Override
            protected void initChannel(EmbeddedChannel ch) {
                ch.pipeline().addLast(inputHandler);
            }
        });
        ByteBuf buf = Unpooled.buffer();
        buf.writeInt(1);
        // 模拟入站，写一个入站包
        channel.writeInbound(buf);
        channel.flush();
        // 模拟入站，再写一个入站包
        channel.writeInbound(buf);
        channel.flush();
        // 通道关闭
        channel.close();
    }
}
